package com.sinopac.action.TokenSynchronous;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.sinopac.actionCore.ActionCore;
import com.sinopac.model.TokenSynchronous.TokenSynchronousModel;


@Namespace("/TokenSynchronous")
@ParentPackage("struts-default")
public class TokenSynchronousAction extends ActionCore{
	
	private static final long serialVersionUID = 1L;
	
	//要傳回錯誤訊息：成功 or 失敗
	private String errorMessage;
	
	//畫面上要帶入的token序號
	private String token_esn;
	
	//畫面上要帶入的失敗代碼
	private int return_code;
	//畫面上要帶入的失敗代碼中文
	private String return_code_ch;
	
	private String synSerCode;//同步序號
	private String synVerifCode;//同步驗證碼
	
	
	@Action(value="execute",results={@Result(name="success",location="/form/TokenSynchronous/TokenSynchronous.jsp")})
	public String execute(){
		token_esn = (String) session.get("token_esn");
		
		return SUCCESS;
	}
	
	@Action(value="tokenSyn",results={@Result(name="success",location="/form/TokenSynchronous/TokenSynchronous.jsp")})
	public String tokenSyn(){
		
		TokenSynchronousModel tsm = new TokenSynchronousModel();
		token_esn = (String) session.get("token_esn");
		//傳入token序號、同步序號、同步驗證碼
		tsm.tokenSynchronous(token_esn,synSerCode,synVerifCode);
		if(StringUtils.isNotBlank(token_esn)){
			session.put(TOKEN_ESN, token_esn);
		}
		
		token_esn = (String) session.get("token_esn");
		return_code = tsm.getReturn_code();
		return_code_ch =tsm.getReturn_code_ch();
		errorMessage = StringUtils.isNotBlank(tsm.getErrorMessage())?tsm.getErrorMessage():"";
		
		return SUCCESS;
	}
	
	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public String getToken_esn() {
		return token_esn;
	}

	public void setToken_esn(String token_esn) {
		this.token_esn = token_esn;
	}
	
	public int getReturn_code() {
		return return_code;
	}

	public void setReturn_code(int return_code) {
		this.return_code = return_code;
	}

	public String getReturn_code_ch() {
		return return_code_ch;
	}

	public void setReturn_code_ch(String return_code_ch) {
		this.return_code_ch = return_code_ch;
	}

	public String getSynSerCode() {
		return synSerCode;
	}

	public void setSynSerCode(String synSerCode) {
		this.synSerCode = synSerCode;
	}

	public String getSynVerifCode() {
		return synVerifCode;
	}

	public void setSynVerifCode(String synVerifCode) {
		this.synVerifCode = synVerifCode;
	}
}
